﻿(function ($) {

    var l = abp.localization.getResource('Edu');//EduResource的LocalizationResourceName特性

    var _appService = edu.services.userAchievement;

    var _createModal = new abp.ModalManager(abp.appPath + 'UserAchievement/CreateModal');

    $(function () {

        var _$wrapper = $('#UserAchievementsWrapper');
        var _$table = _$wrapper.find('table');
        var _dataTable = _$table.DataTable(abp.libs.datatables.normalizeConfiguration({
            order: [],
			processing: true,
			serverSide: true,
			paging: true,
            ajax: abp.libs.datatables.createAjax(_appService.getList),
            columnDefs: [
                {
                    data: "userName"
                },
                {
                    data: "achievementName"
                },
                {
                    data: "achievementIcon",
                    render: function (data) {
                        return '<img width="75" height="75" src="' + data + '">';
                    }
                },
                {
                    rowAction: {
                        items:
                            [
                                {
                                    text: l('Delete'),
                                    visible: abp.auth.isGranted('UserAchievement.UserAchievements.Delete'),
                                    confirmMessage: function (data) { return "你确定删除这条记录吗?"; },
                                    action: function (data) {
                                        _appService
                                            .delete(data.record.id)
                                            .then(function () {
                                                _dataTable.ajax.reload();
                                            });
                                    }
                                }
                            ]
                    }
                }
            ]
        }));

        _createModal.onResult(function () {
            _dataTable.ajax.reload();
        });

        _$wrapper.find('button[name=CreateUserAchievement]').click(function (e) {
            e.preventDefault();
            _createModal.open();
        });
    });

})(jQuery);
